package eu.log;

import eu.config.Config;


public abstract class LogFactory {
	private static LogDaemon daemon = null;
	private static String error=null;
	static {
		//先调用创建storage
		StorageFactory.getDefaultStorage();
		// 获取配置
		Config config = ConfigGetter.getLogConfig();
		if(config==null){
			System.err.println("### Log Config not found,Log disable ###");
			daemon=new NullLogDaemon();
		} else if(error!=null){
			System.err.println("### Error occurs while initialize. Error:"+error+" ###");
			System.err.println("### Log disable ###");
			daemon=new NullLogDaemon();
		}
		else {
			daemon=new SimpleDeamon();
		}
	}
	
	/**
	 * 获取日志守护对象引用
	 */
	public static LogDaemon getDaemon() {
		return daemon;
	}
	
	/**
	 * 获取日志记录器,name为Log所用的ClientIdentity
	 * @param name
	 */
	public static Logger getLogger(String name){
		return new Logger(name);
	}
	
	/**
	 * 获取日志记录器,类名为Log所用的ClientIdentity
	 * @param _class
	 */
	public static Logger getLogger(Class<? extends Object> _class){
		return new Logger(_class.getName());
	}
	
	static void setError(String error){
		LogFactory.error=error;
	}
}
